package com.example.peach;

import android.app.Instrumentation;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    private Button btn_peach;
    private TextView tv_count;
    private int totalCount=0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        init();

    }
    private void init(){
        btn_peach= findViewById(R.id.btn_peach);
        tv_count= findViewById(R.id.tv_count);
        btn_peach.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,PeachActivity.class);
                Bundle extras=new Bundle();
                //extras.putString("key","value");
                startActivityForResult(intent,1);


            }
        });

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent date)
    {
        super.onActivityResult(requestCode, resultCode, date);
        if(requestCode==1&&resultCode==1)
        {
            int count=date.getIntExtra("count",0);
            totalCount=totalCount+count;
            tv_count.setText("摘到"+totalCount+"个");
        }
    }

}